<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="js/vue.js"></script>
  <style>
    .done li {
      text-decoration: line-through;
      color: #999;
    }
    .todo {
      position: relative;
      margin-top: 10px;
    }
    .todo button {
      position: absolute;
      right: 20px;
    }
  </style>
</head>
<body>
  <div id="app">
    <input type="text" v-model="thing" placeholder="请输入代办事项">
    <button v-on:click="add">添加</button>
    <p>待办事项</p>
    <ul>
      <li class="todo" v-for="(item, index) in todoThings">
        <span>{{item}}</span>
        <button v-on:click="done(index)">完成</button>
      </li>
    </ul>
    <hr>
    <p>完成事项</p>
    <ul class="done">
      <li v-for="(item, index) in doneThings">
        <span>{{item}}</span>
      </li>
    </ul>
  </div>
  <script>
    let vm = new Vue({
      el: '#app',
      data: {
        // 输入框中的值
        thing: '',
        // 要做的事情
        todoThings: ['eating', 'sleeping'],
        // 完成的事情
        doneThings: ['coding']
      },
      beforeCreate() {
        // vue实例创建前
        console.log('我是最早的，111');
      },
      created() {
        console.log(222);
      },
      beforeMount() {
        // 渲染，安装
        console.log(333);
      },
      mounted() {
        console.log(444);
      },
      beforeUpdate() {
        // 数据更新
        console.log(555);
      },
      updated() {
        console.log(666);
      },
      beforeDestroy() {
        // 实例销毁前
        console.log(777);
      },
      destroyed() {
        console.log(888);
      },
      methods: {
        // 添加待办事项
        add() {
          if(this.thing != '') {
            this.todoThings.push(this.thing);
            this.thing = '';
          }
        },
        done(index) {
          // 加入到完成事项中
          this.doneThings.push(this.todoThings[index])
          // 删除，从todoThings中剔除
          this.todoThings.splice(index, 1);
        }
      },
    })
  </script>
</body>
</html>